unit ufrmCadPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ufrmMdiChildPadrao, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  ZDataSet, ZAbstractRODataset, uDMConexao, ufrmDialogoPadrao;

type
  TfrmCadPadrao = class(TfrmMdiChildPadrao)
    pnlTool: TPanel;
    btnIncluir: TSpeedButton;
    btnAlterar: TSpeedButton;
    btnExcluir: TSpeedButton;
    btnVisualizar: TSpeedButton;
    btnImprimir: TSpeedButton;
    btnFerramentas: TSpeedButton;
    btnSair: TSpeedButton;
    btnSelecionar: TSpeedButton;
    btnAjuda: TSpeedButton;
    pnPesq: TPanel;
    lbPesquisar: TLabel;
    lbOrdem: TLabel;
    lbl1: TLabel;
    edPesq: TEdit;
    cbOrdemPesq: TComboBox;
    btPesquisar: TBitBtn;
    cbbNomeCampo: TComboBox;
    Grid: TDBGrid;
    procedure GridTitleClick(Column: TColumn);
    procedure GridDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);
    procedure btnSairClick(Sender: TObject);
  private
    { Private declarations }
    procedure Retorno(Sender: TForm; resultado: TModalResult);
  public
    { Public declarations }
  end;

var
  frmCadPadrao: TfrmCadPadrao;

implementation

{$R *.dfm}

procedure TfrmCadPadrao.GridTitleClick(Column: TColumn);
begin
  inherited;
  if TZQuery(Grid.DataSource.DataSet).SortedFields = Column.FieldName then
  begin
    if TZQuery(Grid.DataSource.DataSet).SortType = stascending then
      TZQuery(Grid.DataSource.DataSet).SortType := stDescending
    else
      TZQuery(Grid.DataSource.DataSet).SortType := stAscending;
  end
  else
  begin
    TZQuery(Grid.DataSource.DataSet).SortedFields := Column.FieldName;
    TZQuery(Grid.DataSource.DataSet).SortType := stAscending;
  end;
end;

procedure TfrmCadPadrao.GridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  inherited;
  if TZQuery(Grid.DataSource.DataSet).SortedFields = Column.FieldName then
  begin
    Column.Title.Font.Style := Column.Title.Font.Style + [fsBold];
    if TZQuery(Grid.DataSource.DataSet).SortType = stAscending then
      Column.Title.Color := clMoneyGreen
    else
      Column.Title.Color := clYellow;
  end
  else
  begin
    Column.Title.Font.Style := Column.Title.Font.Style - [fsBold];
    Column.title.Color := clBtnFace;
  end;                              
  Grid.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;

procedure TfrmCadPadrao.FormCreate(Sender: TObject);
begin
  inherited;
  TZQuery(Grid.DataSource.DataSet).Open;
end;

procedure TfrmCadPadrao.btnSairClick(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TfrmCadPadrao.Retorno(Sender: TForm; resultado: TModalResult);
begin
  TZQuery(Grid.DataSource.DataSet).Refresh;
  TZQuery(Grid.DataSource.DataSet).ReadOnly := false;
end;

end.
